#include"include.h"
int parseList(char **str, int size);
int parseStr(char *str);

int main()
{

   int size = 15;
   char *str[] = 
   {
      "i32e",
      "i0e",
      "i-1e",
      "i999999999e",
      "10:bob saggit",
      "50:unicode: !@#$%^&*()_+ 마법소녀 (魔法少女)!",
      "3:마",
      "le",
      "li32ei9999999e10:bob saggit10:teststring1:ti1ei0ei-100ee",
      "lli1ei2ei3eeli-1ei-2ei-3eee",
      "8:announce40:http://tracker.website.com:port/announce7:comment86:Hast Du etwas zeit fur mich Dann singe ich ein Lied fuer Dich Von 99 LuftBalloons!  :)10:created by10:seutorrent13:creation datei1318996742e8:encoding5:UTF-84:info6:lengthi109816527e4:name58:소녀시대(Girls’ Generation／SNSD) – The Boys.fake",
      "de",
      "d3:cow3:moo4:spam4:eggse",
      "d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee",
      "d5:outerd8:innerkey8:innervale11:outerkeytwo11:outervaltwoe"
   };
   parseList(str, size);
   return 0;
}

int parseList(char **str, int size)
{
   int i;
   for(i=0;i<size;i++)
   {
      list_t *l = bdecode(str[i], strlen(str[i]));
      if(l == NULL)
	 return -1;
      printf("String was: %s\n", str[i]);
      resetList(l);
      while(!endList(l))
      {
	 be_dat *d = getObject(l);
	 if(d == NULL)
	    return -1;
	 printBeDat(d);
	 printf(" ");
      }
      printf("\n\n");
   }
   return 0;
}

int parseStr(char *str)
{
   list_t *l = bdecode(str, strlen(str));
   if(l==NULL)
      return -1;
   printf("String was: %s\n", str);
   printf("bdecode is: \n");
   resetList(l);
   while(!endList(l))
   {
      be_dat *d = getObject(l);
      if(l==NULL)
	 return -1;
      printBeDat(d);
      printf(" ");
   }
   printf("\n");

   return 0;
}


